package com.voxel.sense.infomsg.module.publish.personal;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.com.common.view.recycler.RecyclerAdapter;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.voxel.sense.infomsg.R;
import com.voxel.sense.infomsg.module.common.VRecyclerActivity;
import com.voxel.sense.infomsg.module.publish.details.PublishDetActivity;
import com.voxel.sense.infomsg.view.decoration.ItemDivider;
import com.voxel.sense.infomsg.view.decoration.LinearItemDecoration;
import com.voxel.sense.infomsg.view.titlebar.TextTitleBar;

import butterknife.BindView;
import cyy.example.com.facotry.model.api.BaseEntity;
import cyy.example.com.facotry.model.api.MyPublishListEntity;

public class MyPublishActivity extends VRecyclerActivity<MyPublishContract.Presenter, BaseEntity>
        implements MyPublishContract.View<BaseEntity> {

    @BindView(R.id.titlebar)
    TextTitleBar titlebar;
    @BindView(R.id.recycle_view)
    RecyclerView recycle_view;
    private RecyclerAdapter mMyPublishAdapter;

    public static void show(Context context) {
        context.startActivity(new Intent(context, MyPublishActivity.class));
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_my_publish;
    }

    @Override
    protected MyPublishContract.Presenter initPresenter() {
        return new MyPublishPresenter(this);
    }

    @Override
    protected void initData() {
        super.initData();
//        Network
        titlebar.setTitleText("我的填报");
    }

    @Override
    protected void initWidget() {
        super.initWidget();
        initRecyler();
    }

    private void initRecyler() {
        recycle_view.setLayoutManager(new LinearLayoutManager(this));
        recycle_view.addItemDecoration(new LinearItemDecoration(R.drawable.recycle_divider_5dp));
        mMyPublishAdapter = new MyPublishAdapter();
        recycle_view.setAdapter(mMyPublishAdapter);
        refresh_layout.autoRefresh();
    }

    @Override
    public RecyclerAdapter<BaseEntity> getRecyclerViewAdapter() {
        return mMyPublishAdapter;
    }

    @Override
    protected void initEven() {
        super.initEven();
        refresh_layout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                mPresenter.doLoadMore();
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                mPresenter.doRefresh();
            }
        });

        mMyPublishAdapter.setListener(new RecyclerAdapter.AdapterListenerImpl() {
            @Override
            public void onItemClick(RecyclerAdapter.ViewHolder holder, Object o) {
                super.onItemClick(holder, o);
                PublishDetActivity.show((MyPublishListEntity) o, MyPublishActivity.this);
            }
        });
    }

}
